#include <stdio.h>
#include "TpDetec.h"
#include "DoubleList.h"
#include "SlideFunc.h"
#include "BmpShow.h"

extern DNodep Headp;
extern DNodep Tempp;

extern int flag_left;
extern int flag_right;



/**
 * @function: Detect the finger's motion, decide the motion's meaning.
*/
void* SlideMotion_Thread(void * arg)
{
    while(1)
    {
        if(flag_left == 1)
        {
            puts("Show prev pic!");
            //last pic
            lcd_shownext(PREV); 
            flag_left = 0;
        }
        
        if(flag_right == 1)
        {
            puts("Show last pic!");
            //next pic   
            lcd_shownext(NEXT);
            flag_right = 0;
        }
    }
}



void lcd_shownext(char next)
{
    if(next == 0)//prev
    {
        if(Tempp->prev != Headp)
        { 
            Tempp = Tempp->prev;
        }
        else//如果前面没有照片了(Tempp->prev == Headp),重头开始
        {
            Tempp = Headp->prev;   //skip Headp
        }
    }
    else if (next == 1)//next
    {
        if(Tempp->next != Headp)
        { 
            Tempp = Tempp->next;
        }
        else//如果后面没有照片了(Tempp->next == Headp),重头开始
        {
            Tempp = Headp->next;   //skip Headp
        }
    }
    lcd_showbmp_api(Tempp->data, 0,0, 1);
    lcd_showbmp_api(MENU_PIC, 730, 0,0);
}